package org.jetnuke.modules.pictures;

import java.io.PrintWriter;
import java.io.StringWriter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.apache.velocity.Template;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.Velocity;
import org.jetnuke.common.ActionForward;
import org.jetnuke.common.IAction;
import org.jetnuke.common.IAdminInfo;
import org.jetnuke.common.IModuleInfo;
import org.jetnuke.common.IUserInfo;
import org.jetnuke.util.JetUtil;

public class ShowPicture implements IAction {
	private final static Logger s_log = Logger.getLogger(ShowPicture.class);
	
	public ActionForward exec(HttpServletRequest request,
			HttpServletResponse response, VelocityContext vc, IModuleInfo info,
			String op, IUserInfo ui, IAdminInfo ai) throws Exception {
		StringWriter sw = new StringWriter(1024 * 4);
		try {
			Template t = Velocity.getTemplate("modules/pictures/showpicture.vm");
			t.merge(vc, sw);
		} catch (Exception e) {
			s_log.error(e);
		}
		JetUtil.manageReponseCookies(vc,response);
		response.setContentType("text/html");
		String txt = sw.toString();
		
		PrintWriter pw = response.getWriter();
		pw.write(txt);
		return null;
	}

}
